package com.ruoyi.project.WebMoudle.useTerms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.useTerms.domain.UseTerms;
import com.ruoyi.project.WebMoudle.useTerms.service.IUseTermsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 使用条款Controller
 * 
 * @author ruoyi
 * @date 2020-07-13
 */
@Controller
@RequestMapping("/useTerms/useTerms")
public class UseTermsController extends BaseController
{
    private String prefix = "useTerms/useTerms";

    @Autowired
    private IUseTermsService useTermsService;

    @RequiresPermissions("useTerms:useTerms:view")
    @GetMapping()
    public String useTerms()
    {
        return prefix + "/useTerms";
    }


    @GetMapping("/shopUseTerm")
    public String shopUseTerm(ModelMap mmap)
    {
        List<UseTerms> list = useTermsService.selectUseTermsList(null);
        mmap.put("shopUseTerm", list.get(0).getAdvContent());
        return prefix + "/shopUseTerm";
    }

    /**
     * 查询使用条款列表
     */
    @RequiresPermissions("useTerms:useTerms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UseTerms useTerms)
    {
        startPage();
        List<UseTerms> list = useTermsService.selectUseTermsList(useTerms);
        return getDataTable(list);
    }

    /**
     * 导出使用条款列表
     */
    @RequiresPermissions("useTerms:useTerms:export")
    @Log(title = "使用条款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UseTerms useTerms)
    {
        List<UseTerms> list = useTermsService.selectUseTermsList(useTerms);
        ExcelUtil<UseTerms> util = new ExcelUtil<UseTerms>(UseTerms.class);
        return util.exportExcel(list, "useTerms");
    }

    /**
     * 新增使用条款
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存使用条款
     */
    @RequiresPermissions("useTerms:useTerms:add")
    @Log(title = "使用条款", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UseTerms useTerms)
    {
        return toAjax(useTermsService.insertUseTerms(useTerms));
    }

    /**
     * 修改使用条款
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        UseTerms useTerms = useTermsService.selectUseTermsById(id);
        mmap.put("useTerms", useTerms);
        return prefix + "/edit";
    }

    /**
     * 修改使用条款
     */
    @GetMapping("/editOne")
    public String edit(ModelMap mmap)
    {
        List<UseTerms> list = useTermsService.selectUseTermsList(null);
        mmap.put("useTerms", list.get(0));
        return prefix + "/editOne";
    }

    /**
     * 修改保存使用条款
     */
    @RequiresPermissions("useTerms:useTerms:edit")
    @Log(title = "使用条款", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UseTerms useTerms)
    {
        return toAjax(useTermsService.updateUseTerms(useTerms));
    }

    /**
     * 删除使用条款
     */
    @RequiresPermissions("useTerms:useTerms:remove")
    @Log(title = "使用条款", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(useTermsService.deleteUseTermsByIds(ids));
    }
}
